﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace DBA.Common
{
    public class UtilsHelper
    {
        #region 加密和解密
        /// <summary>
        /// 系统提供的基本的DEC加密字符串方法
        /// </summary>
        /// <param name="encryptString">要加密的字符串</param>
        /// <returns></returns>
        public static string Encode(string encryptString)
        {
            return DEncryptHelper.Get(DEncryType.DEC).Encode(encryptString) ;
        }

        /// <summary>
        /// 系统提供的基本的DEC解密字符串方法
        /// </summary>
        /// <param name="decryptString">要解密的字符串</param>
        /// <returns></returns>
        public static string Decode(string decryptString)
        {
            return DEncryptHelper.Get(DEncryType.DEC).Decode(decryptString);
        }

        #endregion

        public static string ServerUrl
        {
            get
            {
                try
                {
                    string path = System.Web.HttpContext.Current.Request.ApplicationPath;
                    if (!path.EndsWith("/")) path += "/";

                    return path;
                }
                catch (Exception)
                {
                    return "/";
                }
            }
        }

        /// <summary>
        /// 获得当前绝对路径
        /// </summary>
        /// <param name="strPath">指定的路径</param>
        /// <returns>绝对路径</returns>
        public static string GetMapPath(string strPath)
        {
            if (HttpContext.Current != null)
            {
                return HttpContext.Current.Server.MapPath(strPath);
            }
            else //非web程序引用
            {
                return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
            }
        }
    }
}
